home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / plane / _Point1.c.ORG < prev    next >
Encoding:
Text File  |  1994-11-16  |  3.2 KB  |  160 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _Point1.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <math.h>
  16. #include <ctype.h>
  17. #include <LEDA/Point1.h>
  18.  
  19. //------------------------------------------------------------------------------
  20. // Points 
  21. //------------------------------------------------------------------------------
  22.  
  23.  
  24. Point_rep::Point_rep()  { count=1; x = y = 0; w = 1;}
  25.  
  26. Point_rep::Point_rep(Int a, Int b) 
  27. { x = a; 
  28.   y = b;
  29.   w = 1; 
  30.   count = 1; 
  31. }
  32.  
  33.  
  34. Point_rep::Point_rep(Int a, Int b, Int c) 
  35. { x = a; 
  36.   y = b;
  37.   w = c; 
  38.   count = 1; 
  39. }
  40.  
  41. Point::Point()                  { PTR = new Point_rep; }
  42. Point::Point(Int x, Int y){ PTR = new Point_rep(x,y); }
  43. Point::Point(Int x, Int y, Int w){ PTR = new Point_rep(x,y,w); }
  44.  
  45. //Point::Point(vector v)          { PTR = new Point_rep(v[0], v[1]); }
  46.  
  47. /*
  48. double Point::angle(const Point& q, const Point& r) const
  49. {
  50.   double cosfi,fi,norm;
  51.   
  52.   double dx  = q.ptr()->x - ptr()->x; 
  53.   double dy  = q.ptr()->y - ptr()->y; 
  54.  
  55.   double dxs = r.ptr()->x - q.ptr()->x; 
  56.   double dys = r.ptr()->y - q.ptr()->y; 
  57.   
  58.   cosfi=dx*dxs+dy*dys;
  59.   
  60.   norm=(dx*dx+dy*dy)*(dxs*dxs+dys*dys);
  61.  
  62.   cosfi /= sqrt( norm );
  63.  
  64.   if (cosfi >=  1.0 ) return 0;
  65.   if (cosfi <= -1.0 ) return M_PI;
  66.   
  67.   fi=acos(cosfi);
  68.  
  69.   if (dx*dys-dy*dxs>0) return fi;
  70.  
  71.   return -fi;
  72. }
  73.   
  74.  
  75. Point Point::rotate(const Point& origin, double alpha) const
  76. { if (origin == *this) return *this;
  77.   segment s(origin,*this);
  78.   return s.rotate(alpha).end();
  79. }
  80.  
  81. Point Point::rotate(double alpha) const
  82. { return rotate(Point(0,0),alpha); }
  83.  
  84. Point Point::translate(double alpha, double d) const
  85. { double dx = cos(alpha) * d;
  86.   double dy = sin(alpha) * d;
  87.   return Point(ptr()->x+dx,ptr()->y+dy);
  88.  }
  89.  
  90. Point Point::translate(const vector& v) const
  91. { return Point(ptr()->x+v[0],ptr()->y+v[1]);
  92.  }
  93.  
  94. double Point::distance(const Point& p)  const
  95. { return hypot(p.ptr()->x - ptr()->x, p.ptr()->y - ptr()->y); } 
  96.  
  97. double Point::distance() const
  98. { return distance(Point(0,0)); }
  99. */
  100.  
  101.  
  102. int Point::operator==(const Point& p) const 
  103. { return ( (((ptr()->x) * (p.ptr()->w) - (p.ptr()->x) * (ptr()->w)) == 0) && 
  104. (((ptr()->y) * (p.ptr()->w) - (p.ptr()->y) * (ptr()->w)) == 0)); }
  105.  
  106.  
  107. ostream& operator<<(ostream& out, const Point& p)
  108. { out << "(" << p.X() << "," << p.Y() << "," << p.W() << ")";
  109.   return out;
  110.  } 
  111.  
  112. istream& operator>>(istream& in, Point& p) 
  113. { // syntax: {(} x {,} y {,} w {)}   
  114.  
  115.   int x,y,w;
  116.   char c;
  117.  
  118.   do in.get(c); while (in && isspace(c));
  119.  
  120.   if (!in) return in;
  121.  
  122.   if (c != '(') in.putback(c);
  123.  
  124.   in >> x;
  125.  
  126.   do in.get(c); while (isspace(c));
  127.   if (c != ',') in.putback(c);
  128.  
  129.   in >> y; 
  130.  
  131.   do in.get(c); while (isspace(c));
  132.   if (c != ',') in.putback(c);
  133.  
  134.   in >> w; 
  135.  
  136.   do in.get(c); while (c == ' ');
  137.   if (c != ')') in.putback(c);
  138.  
  139.   p = Point(x,y,w ); 
  140.   return in; 
  141.  
  142.  } 
  143.  
  144. /*
  145. int compare(const Point& a, const Point& b)
  146. { Int x = a.X() * b.W();
  147.   Int y = b.X() * a.W();
  148.   int s = sign(a.W()) * sign(b.W());
  149.   if (x == y) 
  150.   { x = a.Y() * b.W();
  151.     y = b.Y() * a.W();
  152.     if (x == y) return 0;
  153.    }
  154.   return (x < y) ? -s : s;
  155. }
  156. */
  157.  
  158.  
  159.